Tutorial 1 CSC 201. Java Programming Concepts عؾادئماظربجمةمبادؿكدامماجلاصا

Similar documents
Fundamentals of Programming. By Budditha Hettige

Introduction to Computers and Java

Introduction to Computers and Java. Objectives. Outline. Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich.

Introduction to Computers and Java

Introduction to Computers and Java. Objectives. Outline. Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich.

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 2: SEP. 8TH INSTRUCTOR: JIAYIN WANG

Introduction to Java. Nihar Ranjan Roy.

CT 229. CT229 Lecture Notes. Labs. Tutorials. Lecture Notes. Programming II CT229. Objectives for CT229. IT Department NUI Galway

Java Programming. Zheng-Liang Lu. Java 308 Spring Department of Computer Science & Information Engineering National Taiwan University

CS 11 java track: lecture 1

Lec 3. Compilers, Debugging, Hello World, and Variables

Lesson 01 Introduction

ICOM 4015: Advanced Programming

Lesson 1A - First Java Program HELLO WORLD With DEBUGGING examples. By John B. Owen All rights reserved 2011, revised 2015

9/11/08 (c) 2008 Matthew J. Rutherford Class (c) 2008 Matthew J. Rutherford Class

Java Programming Language Mr.Rungrote Phonkam

From High Level to Machine Code. Compilation Overview. Computer Programs

Java Programming. Zheng-Liang Lu. Java 301 Summer Department of Computer Science & Information Engineering National Taiwan University

Introduction to Java

COMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2016

AP Computer Science A: Java Programming

CSE 421 Course Overview and Introduction to Java

Introduction to Java. Lecture 1 COP 3252 Summer May 16, 2017

Building Java Programs. Introduction to Programming and Simple Java Programs

A PROGRAM IS A SEQUENCE of instructions that a computer can execute to

Certified Core Java Developer VS-1036

Introduction to Computers and Java

Introduction. Introduction to OOP with Java. Lecture 01: Introduction to OOP with Java - AKF Sep AbuKhleiF -

1B1a Programming I Getting Started

PROGRAMMING STYLE. Fundamentals of Computer Science I

Chapter 1. Introduction

Programming with Java

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

COMP1007 Principles of Programming

Chapter 1: Introduction to Computers and Java

8/23/2014. Chapter Topics. Introduction. Java History. Why Program? Java Applications and Applets. Chapter 1: Introduction to Computers and Java

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan

CSE 1223: Introduction to Computer Programming in Java Chapter 1 Computer Basics

Introduction to Java. Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.

How to make a "hello world" program in Java with Eclipse *

C++ Spring Break Packet 11 The Java Programming Language

Goals. Java - An Introduction. Java is Compiled and Interpreted. Architecture Neutral & Portable. Compiled Languages. Introduction to Java

Introduction To Java. Chapter 1. Origins of the Java Language. Origins of the Java Language. Objects and Methods. Origins of the Java Language

AP Computer Science A

II. Compiling and launching from Command-Line, IDE A simple JAVA program

Lab # 2. For today s lab:

Lecture 1: Overview of Java

Welcome to CSE 142! Zorah Fung University of Washington, Spring Building Java Programs Chapter 1 Lecture 1: Introduction; Basic Java Programs

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

CompSci 125 Lecture 02

Chapter 1. Introduction to Computers and Java Objects. Background information. » important regardless of programming language. Introduction to Java

BASICS.

USING THE OOSIML/JAVA. With a Terminal Window

Learning objectives. The Java Environment. Java timeline (cont d) Java timeline. Understand the basic features of Java

Java Bytecode (binary file)

SDKs - Eclipse. SENG 403, Tutorial 2

Index. Course Outline. Grading Policy. Lab Time Distribution. Important Instructions

Lecture 1: Introduction to Java

Getting Started with Java. Atul Prakash

Computer Programming-1 CSC 111. Chapter 1 : Introduction

CS212:Data Structure

Project 1. Java Control Structures 1/17/2014. Project 1 and Java Intro. Project 1 (2) To familiarize with

Darrell Bethea May 10, MTWRF 9:45-11:15 AM Sitterson 011


Welcome to CSE 142! Whitaker Brand. University of Washington, Winter 2018

CS 231 Data Structures and Algorithms, Fall 2016

CSCI 161: Introduction to Programming I Lab 1b: Hello, World (Eclipse, Java)

Java Programming. Zheng-Liang Lu. Java 304 Fall Department of Computer Science & Information Engineering National Taiwan University

ALICE: An introduction to progamming

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

COT 3530: Data Structures. Giri Narasimhan. ECS 389; Phone: x3748

Life Without NetBeans

Introduction to OOP Using Java Pearson Education, Inc. All rights reserved.

CHAPTER 1 Introduction to Computers and Java

Software and Programming 1

Introduction. Lecture 1 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz

Java is a high-level programming language originally developed by Sun Microsystems and released in Java runs on a variety of

JVM interprets the Java bytecode, controls how it interacts with the operating system and manages memory.

Anatomy of a Java Program: Comments

COMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2015

Kickstart Intro to Java Part I

Computer Hardware. Java Software Solutions Lewis & Loftus. Key Hardware Components 12/17/2013

Chapter Goals. Chapter One: Introduction. Prerequisites. What Is Programming?

CSc 2010 Principles of Computer Science, Fall 2013 Practice Problems for Midterm 3* * 3 17 % 9-20 % (26 / 7) "2"

NetBeans IDE Java Quick Start Tutorial

CPS109 Lab 1. i. To become familiar with the Ryerson Computer Science laboratory environment.

Java Language. Programs. Computer programs, known as software, are instructions to the computer. You tell a computer what to do through programs.

IT151: Introduction to Programming (java)

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

CHAPTER INTRODUCTION. Final Draft Oct. 15, Slides by Donald W. Smith TechNeTrain.com. Copyright 2013 by John Wiley & Sons. All rights reserved.

Chapter Goals. Contents. 1.1 Computer Programs

Chapter 1 Introduction to Computers, Programs, and Java

Even though we created a folder for the workspace, we still have to let JCreator do the same. So click File, New, and then Blank Workspace.

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

Chapter 1: A First Program Using C#

Notes of the course - Advanced Programming. Barbara Russo

Java Puzzle Ball Nick Ristuccia

Introduction to Java. Java Programs Classes, Methods, and Statements Comments Strings Escape Sequences Identifiers Keywords

1001ICT Introduction To Programming Lecture Notes

Lesson 04: Our First Java Program (W01D4

Transcription:

Tutorial 1 CSC 201 Java Programming Concepts عؾادئماظربجمةمبادؿكدامماجلاصا

م- م- م- م- م- Chapter 1 1. What is Java? 2. Why Learn Java? a. Java Is Platform Independent b. Java is Easy to learn 3. Programming In Java a. Getting and installing the software b. Creating a Java program 4. Comments 5. Errors a. Syntax Errors b. Logic Errors Summary عامػيماجلاصا ملاذامغؿعؾمماجلاصا اجلاصامالمتعؿؿدمسؾىمبقؽةماظؿشغقل اجلاصامدفؾةماظؿعؾم اظربجمةمبادؿكدامماجلاصا احلصولمسؾىماملشغلموتؾقؿه باءمبرغاعجمبؾغةماجلاصا اظؿعؾقؼات األخطاء أخطاءميفمضواسدماظؽؿابة أخطاءمعطؼقة 1 2 3 4 5

1.What is Java? Java is an object oriented programming language. It has been developed by Sun Microsystems. Java is a high-level language. The Java language goal was to be a small, simple, and portable programming language. ظغةماجلاصامػيمظغةممبرجمةمػقؽؾقةم)باؤػاماألداديمػوماظػؽةممclass (وػيمعنمظغاتمامللؿويماظعاظيم )عػفوعةمظؾؼارئ(موتعؿربمظغةمبرجمةمحمؿوظةمميؽنمادؿكداعفامسؾىماألجفزةموأغظؿةماظؿشغقلماملكؿؾػة.م (Tip: Everything that we have in life is almost an object. A car for example is an object. The TV set is also an object. Now Java is very powerful in representing these types of objects)

2.Why Learn Java? Java is Platform Independent اجلاصامالمتعؿؿدمسؾىمبقؽةماظؿشغقلم ميؽنمتػقذمبرغاعجماجلاصام سؾىمأيمجفازمعؾتمسؾقةمآظةماجلاصاماالصرتاضقةم) JVM ( A platform is the hardware or software environment in which a program runs. Platform independence is one of the most significant features where you can write your code once and run it anywhere that supports a Java virtual machine (JVM). That means that as long as a computer has a JVM, the same program written in the Java programming language can run on Windows 2000, Linux, a Solaris workstation, or on an imac, briefly, on any operating system. This feature will be clearly understood if you know that with most programming languages, you either compile or interpret a program so that you can run it on your computer. Compilations means to translate the file into machine code. Interpretation means to execute the compiled file using another program.

The Java programming language is unusual in that a program is both compiled and interpreted. With the compiler, first you translate a program into an intermediate language called Java "bytecode". The interpreter runs each Java bytecode instruction on the computer. Compilation happens just once and interpretation occurs each time the program is executed. The following figure illustrates how this works.

Java bytecodes help make "write once, run anywhere" possible. You can compile your program into bytecodes on any platform that has a Java compiler. The bytecodes can then be run on any implementation of the Java VM. Java is Easy to Learn ظغةماجلاصامدفؾةماظؿعؾمموضدمصؿؿتمظؿؽونمدفؾةماظؽؿابةم دفؾةماظؿفؿقع دفؾةماظؿصققح,مسؾىماظرشممعنمبلارؿفامصإغفامظغةمضوؼةموعرغة Java was constructed to be a simple programming language. Its initial design goals was for it to be a small and simple language that would be easy to write, easy to compile, and easy to debug. Though its simplicity it is still a very powerful and flexible programming language.

3. Programming in Java اظربجمةمبادؿكدامماجلاصا Creating a Java program إغشاءمبرغاعجمجاصا Create a source file. A source file contains text, written in Java programming language that you and other programmers can understand. You can use any text editor to create and edit source عؾفماملصدرم)طودماظربغاعج(محيؿويمسؾىمغصمعؽؿوبمبؾغةماجلاصامؼلؿطقعمأيمعربعجمأنمؼػفؿه.مميؽكمبادؿكداممأيمحمررم files. غصمإغشاءمأومتعدؼلمعؾفمعصدر /* This program simply displays "Hello World!" on the screen */ class Hello ػذاماظربغاعجمبؾلارةمؼعرضمرداظةمسؾىماظشاذة { public static void main(string[] args) { System.out.println("Hello World!"); } } Note: Java Language is case sensitive, "A" is different than "a". Write the above code and be careful with capital and small letters. اجلاصامحلادةمحلاظةماألحرفم احلرفماظؽؾريمم A مخيؿؾفمسنماحلرفماظصغريم a طنمحذرامسدمطؿابةماظؽود

4. Comments اظؿعؾقؼاتمسؾىماألواعرميفماظربغاعجم جزءمعنماظؽودموظؽفامعفؿؾةمعنماملرتجمممأيم اغفامالمتػذمصائدتفامصؼطماظؿعؾققمسؾىمخطوةمأومذرحمخطوة A comment is a piece of text in a source file that is ignored by the compiler. Comments are used to allow the programmer to express any comment that he/she needs to write about the program. The Java language supports two kinds of comments: /* This is the first kind of comment. It allows you to write comments for any number of lines. A single comment continues until it is terminated with the closing characters. */ // This is the second kind of comment. // It only covers one line. تعؾققمعؿعددماألدطرمممؼؾدأمبمممممم*/م وؼؿفيمبمممممم/* تعؾققمدطرمواحدمؼؾدأمبمممممم//م

5. Errors There are two types of errors: syntax and logic errors. a. Syntax Errors االخطاءم ؼوجدمغوسنيمعنماألخطاءميفماظربغاعج A syntax error is an error in the syntax of the code written. Such an error will cause a compile-time error that prevents the program from running. Missing a semicolon System.out.println("Hello") Unclosed/Unopened Quotation Marks System.out.println("Hello); System.out.println(Hello"); Class Name different from file name Try writing the following code: public class Hello() { public static void main(string[] args) { System.out.println("Hello"); } } Then save the file as a different name than "Hello.java". This will cause a compile-time error because the class and file name do not match. أم خطأميفمضواسدماظؽؿابةمؼلؾبمخطأمأثاءمترمجةماظربغاعجم وميعمتػقذه م عال:مغلقانماظػاصؾةماملؼورةميفمغفاؼةمأيممجؾةم عال:مغلقانمصؿحمأومشؾقمسالعةماظؿصقصم عال:مادمماظؽالسمخمؿؾفمسنمادمماملؾفماملشأمظؾربغاعج

5. Errors a. Syntax Errors أم خطأميفمضواسدماظؽؿابة م عال:ماالخطاءماإلعالئقةم Spelling mistakes public static vod main(string[] args) Case Sensitivity public static void main(string[] args) Un-terminated Comment /* The following statement displays Hello System.out.println("Hello"); The previous will cause a compile-time error because the comment has not been terminated. Using an un-initialized variable public static void main(string[] args) { int x; int y = x +5; } This program will give a compile-time error because the variable x has not been initialized before using it. عال:ماحللادقةمحلاظةماألحرفم عال:مبداؼةمتعؾققموسدممشؾؼهم م عال:مادؿكداممعؿغريمشريمععؾنمسهمأومظقسمظهمضقؿةمعؾدئقة

b. Logic Errors بشؽلمصققحم)خطاميفمعففقةماحللموظقسميفمطؿابةماظربغاعج( A logic error is an error that will not cause an error message. It occurs when the program does not perform what the programmer intended for it to do. With this type of error, the program will compile as well as run, but it will give undesired results. عال:مرؾاسةماظرداظةمبشؽلمخطأميفماظربغاعجماملوضحمدابؼا error: The following is an example of a logic System.out.println("Hell"); The previous statement was meant to print the word "Hello". Instead it will print "Hell". Summary ب خطأمعطؼيمالمؼلؾبمزفورمرداظةمخطأموباظؿاظيمؼػذماظربغاعجموظؽهمالمؼؤديماظعؿؾةماملطؾوبةم غاضشامباخؿصارمظغةماجلاصامطؾغةمبرجمةموممقزاتفاموطقفمميؽكماحلصولمسؾىماظربغاعجماملشغلم وتؾقؿه موسرضامطقفمميؽنمطؿابةمبرغاعجمجاصاموترمجؿهموتػقذه We have briefly discussed Java as a programming language and its advantages. We talked about how to get an install the java software development kit or JSDK. We also have demonstrated how to create, compile and run program.